/*
 * Copyright (C) 2009 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef AWS_WebBindings_h
#define AWS_WebBindings_h

#include "Utilities/PlatformUtils.h"
#include <third_party/npapi/bindings/npruntime.h>

namespace Awesomium {

class WebView;

class WebBindings {
public:
    // NPN Functions ------------------------------------------------------
    // These are all defined in npruntime.h and are well documented.

    // NPN_Construct
    _OSMExport static bool construct(NPP, NPObject*, const NPVariant* args, uint32_t argCount, NPVariant* result);

    // NPN_CreateObject
    _OSMExport static NPObject* createObject(NPP, NPClass*);

    // NPN_Enumerate
    _OSMExport static bool enumerate(NPP, NPObject*, NPIdentifier**, uint32_t* count);

    // NPN_Evaluate
    _OSMExport static bool evaluate(NPP, NPObject*, NPString* script, NPVariant* result);

    // NPN_EvaluateHelper
    _OSMExport static bool evaluateHelper(NPP, bool popupsAllowed, NPObject*, NPString* script, NPVariant* result);

    // NPN_GetIntIdentifier
    _OSMExport static NPIdentifier getIntIdentifier(int32_t number);

    // NPN_GetProperty
    _OSMExport static bool getProperty(WebView* view, NPObject* obj, NPIdentifier propertyName, NPVariant *result);

    // NPN_GetStringIdentifier
    _OSMExport static NPIdentifier getStringIdentifier(const NPUTF8* string);

    // NPN_GetStringIdentifiers
    _OSMExport static void getStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdentifier*);

    // NPN_HasMethod
    _OSMExport static bool hasMethod(NPP, NPObject*, NPIdentifier methodName);

    // NPN_HasProperty
    _OSMExport static bool hasProperty(NPP, NPObject*, NPIdentifier propertyName);

    // NPN_IdentifierIsString
    _OSMExport static bool identifierIsString(NPIdentifier);

    // NPN_InitializeVariantWithStringCopy (though sometimes prefixed with an underscore)
    _OSMExport static void initializeVariantWithStringCopy(NPVariant*, const NPString*);

    // NPN_IntFromIdentifier
    _OSMExport static int32_t intFromIdentifier(NPIdentifier);

    // NPN_Invoke
    _OSMExport static bool invoke(WebView* view, NPObject*, NPIdentifier methodName, const NPVariant* args, uint32_t count, NPVariant* result);

    // NPN_InvokeDefault
    _OSMExport static bool invokeDefault(WebView* view, NPObject*, const NPVariant* args, uint32_t count, NPVariant* result);

    // NPN_ReleaseObject
    _OSMExport static void releaseObject(NPObject*);

    // NPN_ReleaseVariantValue
    _OSMExport static void releaseVariantValue(NPVariant*);

    // NPN_RemoveProperty
    _OSMExport static bool removeProperty(NPP, NPObject*, NPIdentifier);

    // NPN_RetainObject
    _OSMExport static NPObject* retainObject(NPObject*);

    // NPN_SetException
    _OSMExport static void setException(NPObject*, const NPUTF8* message);

    // NPN_SetProperty
    _OSMExport static bool setProperty(NPP, NPObject*, NPIdentifier, const NPVariant*);

    // _NPN_UnregisterObject
    _OSMExport static void unregisterObject(NPObject*);

    // NPN_UTF8FromIdentifier
    _OSMExport static NPUTF8* utf8FromIdentifier(NPIdentifier);

    // NPN_MemAlloc
    _OSMExport static void* memAlloc(uint32);

    // NPN_MemFree
    _OSMExport static void memFree(void*);
};

} // namespace WebKit

#endif
